package com.sunny.common.pojo;

import java.io.Serializable;

public class SunResult implements Serializable{

	private int code = 200;
	private String msg;
	private Object data;
	
	public static SunResult error() {
		return error(500, "未知异常，请联系管理员");
	}
	
	public static SunResult error(String msg) {
		return error(500, msg);
	}
	
	public static SunResult error(int code, String msg) {
		SunResult r = new SunResult();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static SunResult message(int code, String msg) {
		SunResult r = new SunResult();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static SunResult message(int code, String msg, Object data) {
		SunResult r = new SunResult();
		r.setCode(code);
		r.setMsg(msg);
		r.setData(data);
		return r;
	}

	public static SunResult ok() {
		SunResult r = new SunResult();
		r.setCode(200);
		r.setMsg("OK");
		r.setData(null);
		return r;
	}
	
	public static SunResult ok(Object data) {
		SunResult r = new SunResult();
		r.setCode(200);
		r.setMsg("OK");
		r.setData(data);
		return r;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "SunResult{" +
				"code=" + code +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}
}
